package com.qs.imp;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.qs.dao.ConnectionManager;
import com.qs.entity.DailyMessage;

public class DailyMessageImp {
	Connection conn;
	PreparedStatement ps;
	ResultSet rs;

	public List<DailyMessage> getMessage(int dailyid) {
		String sql = "select * from DailyMessage where DailyId=" + dailyid;
		List<DailyMessage> list = new ArrayList<DailyMessage>();
		try {
			conn = ConnectionManager.getConnction();
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				DailyMessage dailymessage = new DailyMessage();
				dailymessage.setDailyId(rs.getInt("DailyId"));
				dailymessage.setMessage(rs.getString("DailyMessage"));
				dailymessage.setUserId(rs.getInt("UserId"));
				dailymessage.setPostTime(rs.getDate("postTime"));
				list.add(dailymessage);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;

	}

	public void newMessage(DailyMessage dailymessage){
		int i = 0;
		String sql = "INSERT INTO DailyMessage(DailyId,DailyMessage,postTime)values(?,?,?)";
	

		try {
			conn = ConnectionManager.getConnction();
			ps = conn.prepareStatement(sql);
			ps.setInt(1, dailymessage.getDailyId());
			ps.setString(2, dailymessage.getMessage());
			ps.setDate(3, dailymessage.getPostTime());

			ps.execute();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
		}

	}

}
